package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;

import cn.stylefeng.guns.sys.modular.system.entity.BtyYhkbg;
import cn.stylefeng.guns.sys.modular.system.entity.GcgWsjdShenpi;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyYhkbgParam;
import cn.stylefeng.guns.sys.modular.system.service.BtyYhkbgService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import java.util.Map;


/**
 * 控制器
 *
 * @author 
 * @Date 2021-06-08 11:49:53
 */
@Controller
@RequestMapping("/btyYhkbg")
public class BtyYhkbgController extends BaseController {

    private String PREFIX = "/modular/system/btyYhkbg";

    @Autowired
    private BtyYhkbgService btyYhkbgService;

    /**
     * 跳转到主页面
     *
     * @author 
     * @Date 2021-06-08
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyYhkbg.html";
    }

    /**
     * 新增页面
     *
     * @author 
     * @Date 2021-06-08
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyYhkbg_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 
     * @Date 2021-06-08
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyYhkbg_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 
     * @Date 2021-06-08
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyYhkbgParam btyYhkbgParam, String account) {
        this.btyYhkbgService.add(btyYhkbgParam, account);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author 
     * @Date 2021-06-08
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyYhkbgParam btyYhkbgParam, String account) {
        this.btyYhkbgService.update(btyYhkbgParam, account);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 
     * @Date 2021-06-08
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyYhkbgParam btyYhkbgParam) {
        this.btyYhkbgService.delete(btyYhkbgParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 
     * @Date 2021-06-08
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyYhkbgParam btyYhkbgParam) {
        BtyYhkbg detail = this.btyYhkbgService.getById(btyYhkbgParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 
     * @Date 2021-06-08
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyYhkbgParam btyYhkbgParam) {
        return this.btyYhkbgService.findPageBySpec(btyYhkbgParam);
    }
    /**
     * 审批通过
     * @author
     * @Date 2021-06-08
     */
    @RequestMapping(value = "/confirmOk")
    @ResponseBody
    public Object confirmOk(@RequestParam Long id) {
    Integer num =  btyYhkbgService.confirmOk(id);
    if(num==3){
       return 3;
    }else if(num==2){
            return 2;
        }
        return SUCCESS_TIP;
    }
    /**
     * 银行卡审批驳回
     * @author
     * @Date 2021-06-08
     */
    @RequestMapping(value = "/bohui")
    @ResponseBody
    public Object bohui(BtyYhkbgParam btyYhkbgParam) {
       Integer num=  btyYhkbgService.bohui(btyYhkbgParam);
        if(num==2){
            return 2;
        }else if(num==3){
            return 3;
        }
         return SUCCESS_TIP;
    }

    /**
     * 银行卡审批
     * @param btyYhkbgParam
     * @param account
     */
    @ResponseBody
    @RequestMapping("/approved")
    public ResponseData approved(BtyYhkbgParam btyYhkbgParam, String account){
        this.btyYhkbgService.approved(btyYhkbgParam, account);
        return ResponseData.success();
    }

    /**
     * 银行卡列表(申请方)
     *
     * @author
     * @Date 2021-06-08
     */
    @ResponseBody
    @RequestMapping("/yhkList")
    public LayuiPageInfo yhkList(BtyYhkbgParam btyYhkbgParam, String account) {
        return this.btyYhkbgService.yhkList(btyYhkbgParam, account);
    }

    /**
     * 银行卡详情-app
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/guyhkById")
    public ResponseData guyhkById(Long id){
        List<Map> list = btyYhkbgService.guyhkById(id);
        return ResponseData.success(list);
    }

    /**
     * 银行卡列表(审核方)
     *
     * @author
     * @Date 2021-06-08
     */
    @ResponseBody
    @RequestMapping("/yhkShList")
    public LayuiPageInfo yhkShList(BtyYhkbgParam btyYhkbgParam, String account) {
        return this.btyYhkbgService.yhkShList(btyYhkbgParam, account);
    }

    /**
     * 银行卡列表(我的列表)
     * 只显示审核通过的
     * @author
     * @Date 2021-06-08
     */
    @ResponseBody
    @RequestMapping("/yhkPassList")
    public ResponseData yhkPassList(BtyYhkbgParam btyYhkbgParam, String account) {
        return this.btyYhkbgService.yhkPassList(btyYhkbgParam, account);
    }

    /**
     * 新增接口-app
     *
     */
    @RequestMapping("/insert")
    @ResponseBody
    public ResponseData insert(BtyYhkbgParam btyYhkbgParam, String account) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String currentDate = format.format(date).substring(8,10);
        //每月1号，2号，14号，15号，不允许变更工资卡
        if (btyYhkbgParam.getYhkyt().equals(1) && (currentDate.equals("1") || currentDate.equals("2") || currentDate.equals("14") || currentDate.equals("15"))){
            return ResponseData.error(502, "每月1号，2号，14号，15号，不允许变更工资卡!");
        }

        return this.btyYhkbgService.insert(btyYhkbgParam, account);
    }


    /**
     * 判断当前登陆者角色接口-app
     *
     */
    @RequestMapping("/roleSta")
    @ResponseBody
    public ResponseData roleSta(String account) {
        return this.btyYhkbgService.roleSta(account);
    }

    /**
     * 获取申请人信息接口-app
     *
     */
    @RequestMapping("/applicant")
    @ResponseBody
    public ResponseData applicant(String name, String account) {
        if (ToolUtil.isEmpty(name) && ToolUtil.isEmpty(account)){
            return ResponseData.error("姓名和电话不能同时为空！");
        }
        List<Map> list = this.btyYhkbgService.applicant(name, account);
        return ResponseData.success(list);
    }


    /**
     * 修改申请接口-app
     *
     */
    @RequestMapping("/update")
    @ResponseBody
    public ResponseData update(BtyYhkbgParam btyYhkbgParam) {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String currentDate = format.format(date).substring(8,10);
        //每月1号，2号，14号，15号，不允许变更工资卡
        if (btyYhkbgParam.getYhkyt().equals(1) && (currentDate.equals("1") || currentDate.equals("2") || currentDate.equals("14") || currentDate.equals("15"))){
            return ResponseData.error(502, "每月1号，2号，14号，15号，不允许变更工资卡!");
        }

        return this.btyYhkbgService.updateApply(btyYhkbgParam);
    }

    /**
     * 查看申请列表接口-app
     */
    @ResponseBody
    @RequestMapping("/applyList")
    public LayuiPageInfo applyList(BtyYhkbgParam btyYhkbgParam, String account) {
        return this.btyYhkbgService.applyList(btyYhkbgParam, account);
    }

    /**
     * 校验银行卡信息-app
     */
    @ResponseBody
    @RequestMapping("/checkYhk")
    public ResponseData checkYhk(String yhkNum) {
        return this.btyYhkbgService.checkYhk(yhkNum);
    }

    /**
     * 跳转到工资卡变更页面
     *
     */
    @RequestMapping("/wagesYhkbg")
    public String wagesYhkbg() {
        return PREFIX + "/wagesYhkbg.html";
    }

    /**
     * 跳转到分红卡变更页面
     *
     */
    @RequestMapping("/bonusYhkbg")
    public String bonusYhkbg() {
        return PREFIX + "/bonusYhkbg.html";
    }

    /**
     * 工资卡初始化门店-PC
     */
    @ResponseBody
    @RequestMapping("/dmList")
    public ResponseData dmList() {
        return this.btyYhkbgService.dmList();
    }

    /**
     * 工资卡初始化营运经理-PC
     */
    @ResponseBody
    @RequestMapping("/yyjlList")
    public ResponseData yyjlList() {
        return this.btyYhkbgService.yyjlList();
    }

    /**
     * 工资卡初始化督导-PC
     */
    @ResponseBody
    @RequestMapping("/ddList")
    public ResponseData ddList(String yyjl) {
        return this.btyYhkbgService.ddList(yyjl);
    }

    /**
     * 工资卡变更审核列表-PC
     */
    @ResponseBody
    @RequestMapping("/wagesList")
    public LayuiPageInfo wagesList(BtyYhkbgParam btyYhkbgParam) {
        return this.btyYhkbgService.wagesList(btyYhkbgParam);
    }

    /**
     * 工资卡审批接口-PC
     */
    @ResponseBody
    @RequestMapping("/wagesApproved")
    public ResponseData wagesApproved(BtyYhkbgParam btyYhkbgParam) {
        return this.btyYhkbgService.wagesApproved(btyYhkbgParam);
    }

    /**
     * 分红卡变更审核列表-PC
     */
    @ResponseBody
    @RequestMapping("/bonusList")
    public LayuiPageInfo bonusList(BtyYhkbgParam btyYhkbgParam) {
        return this.btyYhkbgService.bonusList(btyYhkbgParam);
    }

    /**
     * 分红卡审批接口-PC
     */
    @ResponseBody
    @RequestMapping("/bonusApproved")
    public ResponseData bonusApproved(BtyYhkbgParam btyYhkbgParam) {
        return this.btyYhkbgService.bonusApproved(btyYhkbgParam);
    }

    /**
     * 批量审批通过接口-PC
     */
    @ResponseBody
    @RequestMapping("/batchApproved")
    public ResponseData batchApproved(@RequestParam("ids") String ids, Integer yhkyt) {
        return this.btyYhkbgService.batchApproved(ids, yhkyt);
    }
}


